#include <cstdio>
#include <cstring>
int main()
{
    char str[100001] = {0};
    scanf("%s", str);
    int len = strlen(str);
    int i, j, k;
    int firstA, lastT;
    int countP = 0, countT = 0;
    for (i = 0; i < len; ++i)
    { //找到第一个A在序列当中的位置
        if ('P' == str[i])
        {
            ++countP;
        }
        else if ('A' == str[i])
        {
            firstA = i;
            break;
        }
    }
    for (k = len - 1; k > firstA; --k)
    {
        if ('T' == str[k])
        {
            if (0 == countT)
            {
                lastT = k;
            }
            ++countT;
        }
    }
    long long int count = 0;
    for (j = firstA; j < lastT; ++j)
    {
        if ('P' == str[j])
            ++countP;
        else if ('T' == str[j])
            --countT;
        else if ('A' == str[j])
            count += countP * countT;
    }
    printf("%ld\n", count % 1000000007);
    return 0;
}